package com.douqu.game.core.entity.ext.data.boon;

import com.bean.core.buffer.ByteBuffer;
import com.douqu.game.core.config.InitDataConfig;
import com.douqu.game.core.config.LotteryConfig;
import com.douqu.game.core.config.StableDataConfig;
import com.douqu.game.core.controller.PlayerController;
import com.douqu.game.core.e.E_InitDataType;
import com.douqu.game.core.e.E_LotteryType;
import com.douqu.game.core.e.E_StableDataType;
import com.douqu.game.core.entity.Player;
import com.douqu.game.core.entity.db.*;
import com.douqu.game.core.entity.ext.BagInfo;
import com.douqu.game.core.entity.ext.TaskInfo;
import com.douqu.game.core.entity.ext.data.BaseData;
import com.douqu.game.core.factory.*;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.protobuf.SGMainProto;
import com.douqu.game.core.protobuf.SGPlayerProto;
import com.douqu.game.core.util.CoreUtils;
import com.douqu.game.core.util.LogUtils;

import java.util.List;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2017-10-30 17:05
 */
public class OldLotteryData extends BaseData {

//    /**
//     * 抽奖次数
//     * key: 类型
//     * value: 抽奖数据
//     */
//    public Map<Integer,SingleBoonData> lotteryMap;

    /**
     * 定时器是否推送过了
     */
    public boolean hasPushRedPointRemind = false;
    private LotteryDB goldSingleDB;
    private LotteryDB goldMuchDB;
    private LotteryDB diamondSingleDB;
    private LotteryDB diamondMuchDB;
    private Player player;

    public OldLotteryData(Player player) {
        this.player = player;
//        lotteryMap = new ConcurrentHashMap<>();
        hasPushRedPointRemind = false;

        goldSingleDB = new LotteryGoldSingleDB(DataFactory.LOTTERY_KEY);
        goldMuchDB = new LotteryGoldMuchDB(DataFactory.LOTTERY_KEY);
        diamondSingleDB = new LotteryDiamondSingleDB(DataFactory.LOTTERY_KEY);
        diamondMuchDB = new LotteryDiamondMuchDB(DataFactory.LOTTERY_KEY);
    }

    @Override
    public void init() {
        List<LotteryConfig> list = DataFactory.getInstance().getDataList(DataFactory.LOTTERY_KEY);
        for (LotteryConfig object : list) {
            if (object.type == 1 && object.level == 1)
                goldSingleDB = new LotteryGoldSingleDB(DataFactory.LOTTERY_KEY, object.id);
            else if (object.type == 1 && object.level == 2)
                goldMuchDB = new LotteryGoldMuchDB(DataFactory.LOTTERY_KEY, object.id);
            else if (object.type == 2 && object.level == 1)
                diamondSingleDB = new LotteryDiamondSingleDB(DataFactory.LOTTERY_KEY, object.id);
            else if (object.type == 2 && object.level == 2)
                diamondMuchDB = new LotteryDiamondMuchDB(DataFactory.LOTTERY_KEY, object.id);

        }
    }

    @Override
    public void checkInit() {

        if (goldSingleDB.id == 0) {
            init();
        }
    }

    @Override
    public void reset() {
        goldSingleDB.reset();
        goldMuchDB.reset();
        diamondSingleDB.reset();
        diamondMuchDB.reset();
    }

    @Override
    public void checkReset() {

        if (!goldSingleDB.isTodayByOffset() || !diamondSingleDB.isTodayByOffset()) {
            reset();
        }
    }

    @Override
    public void writeTo(ByteBuffer buffer) {
        goldSingleDB.writeTo(buffer);
        goldMuchDB.writeTo(buffer);
        diamondSingleDB.writeTo(buffer);
        diamondMuchDB.writeTo(buffer);
    }

    @Override
    public void loadFrom(ByteBuffer buffer) {
        goldSingleDB.loadFrom(buffer);
        goldMuchDB.loadFrom(buffer);
        diamondSingleDB.loadFrom(buffer);
        diamondMuchDB.loadFrom(buffer);
    }


    /**
     * 是否有红点
     *
     * @return
     */
    public boolean hasRedPointRemind(boolean isScheduleTask, long currentTime) {
        if (hasPushRedPointRemind && isScheduleTask) {
            return false;
        }
        boolean has = false;

        if (goldSingleDB.getFreeCount() > 0)
            has = goldSingleDB.getCDTime() <= 0;

        if (!has && diamondSingleDB.getFreeCount() > 0)
            has = diamondSingleDB.getCDTime() <= 0;

        if (has && isScheduleTask) {
            hasPushRedPointRemind = true;
        }
        return has;
    }

//    /**
//     * 抽奖
//     * @param playerController
//     * @param type
//     * @param buyType
//     */
//    public void getCommonLottery(PlayerController playerController, int type, int buyType)
//    {
//        if(type != E_LotteryType.ONCE.getCode() && type != E_LotteryType.REPEATEDLY.getCode())
//        {
//            playerController.sendWarn(WordFactory.ILLEGAL_ERROR);
//            return;
//        }
//        if(buyType != E_LotteryType.ONCE.getCode() && buyType != E_LotteryType.REPEATEDLY.getCode())
//        {
//            playerController.sendWarn(WordFactory.ILLEGAL_ERROR);
//            return;
//        }
//
//        //获取抽奖数据
//        SingleBoonData lotteryData = lotteryMap.get(type);
//        if(lotteryData == null) {
//            playerController.sendWarn(WordFactory.CURRENT_LOTTERY);
//            return;
//        }
//        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
//        SGPlayerProto.S2C_LotteryClick.Builder b = SGPlayerProto.S2C_LotteryClick.newBuilder();
//
//        LotteryConfig  lotteryConfig = DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY, lotteryData.id);
//        long currentTime = DataFactory.currentTime;
//        if (type == E_LotteryType.ONCE.getCode() ){
//            if(buyType == E_LotteryType.ONCE.getCode()){
//                if((lotteryData.currentNum + 1) % lotteryConfig.nextLevelCount == 0){
//                    lotteryConfig = DataFactory.getInstance().getNextLevelLottery(type, lotteryConfig.level);
//                }
//
//            }else{
//                lotteryConfig = DataFactory.getInstance().getNextLevelLottery(type, lotteryConfig.level);
////                deduction  = lotteryConfig.needAsset.value;
//            }
//        } else {
//            if(buyType == E_LotteryType.ONCE.getCode()){
//                if((lotteryData.currentNum + 1) % lotteryConfig.nextLevelCount == 0){
//                    lotteryConfig = DataFactory.getInstance().getNextLevelLottery(type, lotteryConfig.level);
//                }
////                deduction  = lotteryConfig.needAsset.value ;
//            }else{
//
//
//                LotteryConfig tenObject = DataFactory.getInstance().getNextLevelLottery(type, lotteryConfig.level);
//                if(lotteryData.fistSeniorLotteryTime == 0){
//                    lotteryConfig = DataFactory.getInstance().getNextLevelLottery(type, tenObject.level);
//                }else{
//                    int c = lotteryData.currentNum;
//                    int d = (c/40 +1) * 40;
//                    if (c <= d  && d <= c+10 &&  (c % 40 != 0)){
//                        lotteryConfig = DataFactory.getInstance().getNextLevelLottery(type, tenObject.level);
////                    deduction = lotteryConfig.needAsset.value ;
//                    } else {
//                        lotteryConfig = tenObject;
////                    deduction = lotteryConfig.needAsset.value ;
//                    }
//                }
//
//            }
//        }
//        int deduction = 0;
//        GoodsData bisong = lotteryConfig.reward;
//        if(type == E_LotteryType.ONCE.getCode() ){
//            if(buyType == E_LotteryType.ONCE.getCode()){
//                deduction  = 10000 ;
//            }else if (buyType == E_LotteryType.REPEATEDLY.getCode()){
//                deduction  = 10000 * 10;
//            }
//        }else if (type == E_LotteryType.REPEATEDLY.getCode()){
//            if(buyType == E_LotteryType.ONCE.getCode()){
//                deduction  = 300 ;
//            }else if (buyType == E_LotteryType.REPEATEDLY.getCode()){
//                deduction  = 2800;
//                bisong = lotteryConfig.reward.copyNew();
//                bisong.value = 500;
//            }
//        }
//
//
//        boolean cdTimeFlag = buyType == E_LotteryType.ONCE.getCode() && currentTime - lotteryData.lastUpdateTime >= lotteryConfig.cdTime;
//        //没有免费次数检测cd时间是否未到
//        if(lotteryData.freeCount <= 0 || !cdTimeFlag) {
//
//
//            //检测资源是否足够
//            if(bagInfo.getAsset(lotteryConfig.needAsset.id) < deduction) {
//                //资源不够
//                LogUtils.debug("钻石不够,需要 -> " + lotteryConfig.needAsset.value + " " + lotteryConfig.getName());
//                playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, lotteryConfig.needAsset.id);
//                return;
//            }
//
//        }
//
//        if(lotteryData.freeCount > 0) {
//            if(!cdTimeFlag){
//                bagInfo.addAsset(lotteryConfig.needAsset.id, -deduction);
//            }
//            else
//            {
//                lotteryData.freeCount--;
//            }
//        } else {
//            //扣除资源
//            bagInfo.addAsset(lotteryConfig.needAsset.id, -deduction);
//        }
//
//        bagInfo.addGoods(bisong, true);
//        //抽奖
//        if(buyType  == E_LotteryType.ONCE.getCode()){
//
//            //刷新次数
//            lotteryData.currentNum++;
//            if(lotteryData.currentNum  >= 10 ){
//                lotteryData.currentNum -=10;
//            }
//            lotteryData.lastUpdateTime = currentTime;
//            initLotteryResponse(playerController, false);
//            //如果是钻石（高级）抽奖并且抽奖次数是0走初始化配置
//            if(type == E_LotteryType.REPEATEDLY.getCode() && lotteryData.firstLotteryTime == 0){
//                InitDataConfig initDataConfig = DataFactory.getInstance().getInitDataConfig();
//                for (CommonData commonData: initDataConfig.firstLotteryReward){
//                    if(commonData.id == playerController.getPlayer().camp){
//                        bagInfo.addCard(commonData.value,1);
//                        break;
//                    }
//                }
//
//                lotteryData.firstLotteryTime = DataFactory.currentTime;
//
//            }else{
//                bagInfo.addGoods(lotteryConfig.getDrop());
//            }
//
//        }else{
//            if(type == E_LotteryType.REPEATEDLY.getCode() ){
//                lotteryData.fistSeniorLotteryTime = DataFactory.currentTime;
//            }
//
//            LotteryConfig onceLotteryConfig = DataFactory.getInstance().getInitLevelLottery(lotteryConfig.type);
//            //刷新次数
//            lotteryData.currentNum += 10;
//            if(lotteryData.currentNum >= 40){
//                lotteryData.currentNum -=40;
//            }
//            initLotteryResponse(playerController,false);
////            //循环9次获取奖励
//            for (int i = 0; i < 9; i++) {
//                bagInfo.addGoods(onceLotteryConfig.getDrop());
//            }
//            bagInfo.addGoods(lotteryConfig.getDrop());
//        }
//        b = refreshSeniorLotteryData(b);
//        playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Pub_LotteryClick_VALUE, b.build().toByteArray());
//
//        //抽奖之后检测是否完成任务
////        taskInfo.checkFinish(ConstantFactory.TASK_TARAGET_LOTTERY, type == E_LotteryType.REPEATEDLY.getCode() ? 10 :E_LotteryType.ONCE.getCode());
//
//
//        FunctionConfig functionConfig = DataFactory.getInstance().getGameObject(DataFactory.FUNCTION_KEY, DataFactory.EVERY_TASK);
//        List<TaskDB> taskDBList = null;
//        if(player.getLv() >= functionConfig.lv){
//            TaskInfo taskInfo = playerController.getPlayer().getExtInfo(TaskInfo.class);
//            //酒馆邂逅
//            if(type == E_LotteryType.ONCE.getCode()){
//                //酒馆邂逅
//                taskDBList = taskInfo.getDoingEveryTask(ConstantFactory.TASK_TARAGET_LOTTERY);
//                for(TaskDB taskDB : taskDBList){
//                    if(taskDB.status == SGCommonProto.E_TASK_STATUS.TASK_STATUS_UNDERWAY_VALUE){
//                        taskDB.check(ConstantFactory.TASK_TARAGET_LOTTERY, 1);
//                    }
//                }
//            }else{
//                taskDBList = taskInfo.getDoingEveryTask(ConstantFactory.TASK_TARAGET_EVERYDAY_LOTTERY);
//                for(TaskDB taskDB : taskDBList){
//                    if(taskDB.status == SGCommonProto.E_TASK_STATUS.TASK_STATUS_UNDERWAY_VALUE){
//                        taskDB.check(ConstantFactory.TASK_TARAGET_EVERYDAY_LOTTERY, 1);
//                    }
//                }
//            }
//
//        }
//    }


    /**
     * 抽奖
     *
     * @param playerController
     * @param type
     * @param buyType
     */
    public void getCommonLottery(PlayerController playerController, int type, int buyType) {
        if (type != E_LotteryType.ONCE.getCode() && type != E_LotteryType.REPEATEDLY.getCode()) {
            playerController.sendWarn(WordFactory.ILLEGAL_ERROR);
            return;
        }
        if (buyType != E_LotteryType.ONCE.getCode() && buyType != E_LotteryType.REPEATEDLY.getCode()) {
            playerController.sendWarn(WordFactory.ILLEGAL_ERROR);
            return;
        }

        LotteryConfig lotteryConfig = DataFactory.getInstance().getLotteryConfig(type, buyType);
        if (lotteryConfig == null) {
            LogUtils.error("lotteryConfig is null");
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        //获取抽奖数据
        LotteryDB lotteryDB = getLotteryDB(lotteryConfig.id);
        if (lotteryDB == null) {
            LogUtils.error("lotteryDB is null");
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        LotteryConfig finalLotteryConfig = null;
        int stableCardId = 0;
        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        LotteryConfig initLotteryConfig = DataFactory.getInstance().getInitLevelLottery(type);

        if (buyType == E_LotteryType.ONCE.getCode()) {

            if (!lotteryDB.checkFreeCount()) {
                //检测资源是否足够
                if (bagInfo.getAsset(lotteryConfig.needAsset.id) < lotteryConfig.needAsset.value) {
                    //资源不够
                    LogUtils.debug("资源不够,需要 -> " + lotteryConfig.needAsset.value + " " + lotteryConfig.getName());
                    playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, lotteryConfig.needAsset.id);
                    return;
                }

                bagInfo.addAsset(lotteryConfig.needAsset.id, -lotteryConfig.needAsset.value);

            }

            if (lotteryDB instanceof LotteryDiamondSingleDB) {
                if (!((LotteryDiamondSingleDB) lotteryDB).flag) {

                    StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.FIRST_LOTTERY_REWARD.getCode());
                    if (stableDataConfig == null){
                        LogUtils.error("StableDataConfig error ->" + "no have type " + E_StableDataType.FIRST_LOTTERY_REWARD.getMsg());
                        return;
                    }
                    stableCardId = stableDataConfig.getFistCardId(playerController.getPlayer().camp);
                    finalLotteryConfig = lotteryConfig;
                }
            }
            if (stableCardId == 0 && finalLotteryConfig == null) {
                if ((lotteryDB.currentNum + 1) % initLotteryConfig.nextLevelCount == 0) {
                    finalLotteryConfig = DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY, lotteryConfig.nextLevelPond);
                } else {
                    finalLotteryConfig = lotteryConfig;
                }
            }

            bagInfo.addGoods(finalLotteryConfig.reward, true);

            if (stableCardId != 0) {
                bagInfo.addCard(stableCardId, 1);
            } else {
                bagInfo.addGoods(finalLotteryConfig.getDrop());
            }

            lotteryDB.addCurrentCount();
        } else {
            int deduction = 0;
            if (type == E_LotteryType.ONCE.getCode()) {
                deduction = 10000 * 10;
            } else if (type == E_LotteryType.REPEATEDLY.getCode()) {
                deduction = 2800;
            }


            //检测资源是否足够
            if (bagInfo.getAsset(lotteryConfig.needAsset.id) < deduction) {
                //资源不够
                LogUtils.debug("资源不够,需要 -> " + deduction + " " + lotteryConfig.getName());
                playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, lotteryConfig.needAsset.id);
                return;
            }

            bagInfo.addAsset(lotteryConfig.needAsset.id, -deduction);

            if (lotteryDB instanceof LotteryDiamondMuchDB) {
                StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.DIAMOND_MUCH_STABLE.getCode());
                stableCardId = stableDataConfig.getDiamondMuchLotteryCardId(playerController.getPlayer().camp, lotteryDB.currentNum);
                if (stableCardId == 0) {
                    if ((lotteryDB.currentNum + 1) % lotteryConfig.nextLevelCount == 0) {
                        finalLotteryConfig = DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY, lotteryConfig.nextLevelPond);
                    } else {
                        finalLotteryConfig = lotteryConfig;
                    }
                }
//                if(!((LotteryDiamondMuchDB) lotteryDB).flag)
//                    finalLotteryConfig = DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY,lotteryConfig.nextLevelPond);
//                else
//                {
//                    if((lotteryDB.currentNum + 1 )% lotteryConfig.nextLevelCount == 0){
//                        finalLotteryConfig = DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY,lotteryConfig.nextLevelPond);
//                    }else {
//                        finalLotteryConfig = lotteryConfig;
//                    }
//                }
            } else if (lotteryDB instanceof LotteryGoldMuchDB) {
                finalLotteryConfig = lotteryConfig;
            }


            bagInfo.addGoods(lotteryConfig.reward, true);

            for (int i = 0; i < 9; i++) {
                bagInfo.addGoods(initLotteryConfig.getDrop());
            }

            if (stableCardId != 0)
                bagInfo.addCard(stableCardId, 1);
            else
                bagInfo.addGoods(finalLotteryConfig.getDrop());

            lotteryDB.addCurrentCount();
        }

        lotteryDB.setCdTime();

        refreshSeniorLotteryData(playerController);

        //酒馆邂逅
        if (type == E_LotteryType.ONCE.getCode()) {
            playerController.getPlayer().getExtInfo(TaskInfo.class).check(TaskFactory.TASK_TARAGET_LOTTERY, 1);
        } else {
            playerController.getPlayer().getExtInfo(TaskInfo.class).check(TaskFactory.TASK_TARAGET_EVERYDAY_LOTTERY, 1);
            //检测开服活动是否完成
            playerController.getPlayer().getSevenDayData().checkAllRewardState(SevenDayFactory.EVENT_TYPE_4,1);
        }
    }

    /***
     * 酒馆初始化
     * @param playerController
     */
    public void initLotteryResponse(PlayerController playerController) {
        hasPushRedPointRemind = false;
        SGPlayerProto.S2C_LotteryInit.Builder response = SGPlayerProto.S2C_LotteryInit.newBuilder();

        LotteryConfig goldSingleLotteryConfig = DataFactory.getInstance().getLotteryConfig(E_LotteryType.ONCE.getCode(), E_LotteryType.ONCE.getCode());
        LotteryConfig diamondSingleLotteryConfig = DataFactory.getInstance().getLotteryConfig(E_LotteryType.REPEATEDLY.getCode(), E_LotteryType.ONCE.getCode());
        LotteryConfig diamondMuchLotteryConfig = DataFactory.getInstance().getLotteryConfig(E_LotteryType.REPEATEDLY.getCode(), E_LotteryType.REPEATEDLY.getCode());
        LotteryDB goldSingleLotteryDB = getLotteryDB(goldSingleLotteryConfig.id);
        LotteryDB diamondSingleLotteryDB = getLotteryDB(diamondSingleLotteryConfig.id);
        LotteryDB diamondMuchLotteryDB = getLotteryDB(diamondMuchLotteryConfig.id);

        int leftResidueCount = goldSingleLotteryConfig.nextLevelCount - goldSingleLotteryDB.currentNum % goldSingleLotteryConfig.nextLevelCount - 1;
        int rightResidueCount = diamondSingleLotteryConfig.nextLevelCount - diamondSingleLotteryDB.currentNum % diamondSingleLotteryConfig.nextLevelCount - 1;
        int rightResidueCount2 = diamondMuchLotteryConfig.nextLevelCount - diamondMuchLotteryDB.currentNum % diamondMuchLotteryConfig.nextLevelCount - 1;

        response.setLeftFreeCount(goldSingleLotteryDB.getFreeCount());
        response.setRightFreeCount(diamondSingleLotteryDB.getFreeCount());

        response.setLeftCDTime(goldSingleLotteryDB.getCDTime());
        response.setRightCDTime(diamondSingleLotteryDB.getCDTime());

        response.setLeftResidueCount(leftResidueCount);
        response.setRightResidueCount(rightResidueCount);
        response.setRightResidueCount2(rightResidueCount2);

        LogUtils.debug("response -> " + response);

        playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Pub_LotteryInit_VALUE, response.build().toByteArray());

    }

    /***
     * 酒馆初始化
     * @param playerController
     */
//    public void initLotteryResponse(PlayerController playerController,boolean bl) {
//        hasPushRedPointRemind = false;
//
//        SGPlayerProto.S2C_LotteryInit.Builder b = SGPlayerProto.S2C_LotteryInit.newBuilder();
//        SingleBoonData lotteryData = null;
//        LotteryConfig initLotteryConfig = null;
//        //获取次数和剩余CD时间
//        long currentTime = DataFactory.currentTime;
//        lotteryData = lotteryMap.get(1);
//        int leftFreeCount = lotteryData.freeCount;
//        initLotteryConfig = DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY, lotteryData.id);
//        int temp = lotteryData.lastUpdateTime  == 0 ? 0 : (int) (currentTime - lotteryData.lastUpdateTime);
//        int leftCDTime;
//        if(lotteryData.lastUpdateTime == 0){
//            leftCDTime = 0;
//        }else{
//            leftCDTime = temp > initLotteryConfig.cdTime ? 0 : initLotteryConfig.cdTime - temp;
//        }
//        int leftResidueCount = initLotteryConfig.nextLevelCount - lotteryData.currentNum % initLotteryConfig.nextLevelCount - 1;
//        lotteryData = lotteryMap.get(2);
//        int rightFreeCount = lotteryData.freeCount;
//        initLotteryConfig = DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY, lotteryData.id);
//        temp = lotteryData.lastUpdateTime  == 0 ? 0 : (int) (currentTime - lotteryData.lastUpdateTime);
//        int rightCDTime;
//        if(lotteryData.lastUpdateTime == 0){
//            rightCDTime = 0;
//        }else{
//            rightCDTime  = temp > initLotteryConfig.cdTime ? 0 : initLotteryConfig.cdTime - temp;
//        }
//        int rightResidueCount = initLotteryConfig.nextLevelCount - lotteryData.currentNum % initLotteryConfig.nextLevelCount - 1;
//        LotteryConfig highLotteryConfig = DataFactory.getInstance().getNextLevelLottery(initLotteryConfig.type, initLotteryConfig.level);
//        int rightResidueCount2 = highLotteryConfig.nextLevelCount - (lotteryData.currentNum / initLotteryConfig.nextLevelCount) % highLotteryConfig.nextLevelCount - 1;
//
//        b.setLeftFreeCount(leftFreeCount);
//        b.setLeftCDTime(leftCDTime);
//        b.setLeftResidueCount(leftResidueCount);
//        b.setRightFreeCount(rightFreeCount);
//        b.setRightCDTime(rightCDTime);
//        b.setRightResidueCount(rightResidueCount);
//        b.setRightResidueCount2(rightResidueCount2);
//
//        if(bl){
//            playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Pub_LotteryInit_VALUE, b.build().toByteArray());
//        }
//    }


//    public SGPlayerProto.S2C_LotteryClick.Builder refreshSeniorLotteryData(SGPlayerProto.S2C_LotteryClick.Builder b)
//    {
//        SingleBoonData lotteryData = null;
//        LotteryConfig initLotteryConfig = null;
//        lotteryData = lotteryMap.get(2);
//        initLotteryConfig = DataFactory.getInstance().getGameObject(DataFactory.LOTTERY_KEY, lotteryData.id);
//        int rightResidueCount = initLotteryConfig.nextLevelCount - lotteryData.currentNum % initLotteryConfig.nextLevelCount -1;
//        LotteryConfig highLotteryConfig = DataFactory.getInstance().getNextLevelLottery(initLotteryConfig.type, initLotteryConfig.level);
//        int rightResidueCount2 =  highLotteryConfig.nextLevelCount - (lotteryData.currentNum / initLotteryConfig.nextLevelCount) % highLotteryConfig.nextLevelCount -1;
//        b.setRightResidueCount(rightResidueCount);
//        b.setRightResidueCount2(rightResidueCount2);
//        return b;
//    }
    public void refreshSeniorLotteryData(PlayerController playerController) {
        LotteryConfig lotteryConfig1 = DataFactory.getInstance().getLotteryConfig(E_LotteryType.REPEATEDLY.getCode(), E_LotteryType.ONCE.getCode());
        LotteryConfig lotteryConfig2 = DataFactory.getInstance().getLotteryConfig(E_LotteryType.REPEATEDLY.getCode(), E_LotteryType.REPEATEDLY.getCode());
        LotteryDB lotteryDB1 = getLotteryDB(lotteryConfig1.id);
        LotteryDB lotteryDB2 = getLotteryDB(lotteryConfig2.id);

        SGPlayerProto.S2C_LotteryClick.Builder response = SGPlayerProto.S2C_LotteryClick.newBuilder();

        int rightResidueCount = lotteryConfig1.nextLevelCount - lotteryDB1.currentNum % lotteryConfig1.nextLevelCount - 1;
        int rightResidueCount2 = lotteryConfig2.nextLevelCount - lotteryDB2.currentNum % lotteryConfig2.nextLevelCount - 1;
        response.setRightResidueCount(rightResidueCount);
        response.setRightResidueCount2(rightResidueCount2);
        playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Pub_LotteryClick_VALUE, response.build().toByteArray());
    }


    public LotteryDB getLotteryDB(int id) {
        if (id == goldSingleDB.id)
            return goldSingleDB;

        if (id == goldMuchDB.id)
            return goldMuchDB;

        if (id == diamondSingleDB.id)
            return diamondSingleDB;

        if (id == diamondMuchDB.id)
            return diamondMuchDB;

        LogUtils.error("获取抽奖对象错误, ID -> " + id);
        return null;
    }

}
